﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Assessment.Model;

namespace Assessment.BLL {
	 	//T_Assessment
		public partial class T_AssessmentBLL
	{
   		     
		private readonly Assessment.DAL.T_AssessmentDAL dal=new Assessment.DAL.T_AssessmentDAL();
		public T_AssessmentBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int AssessmentId)
		{
			return dal.Exists(AssessmentId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Assessment.Model.T_Assessment model)
		{
						return dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Assessment.Model.T_Assessment model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int AssessmentId)
		{
			
			return dal.Delete(AssessmentId);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string AssessmentIdlist )
		{
			return dal.DeleteList(AssessmentIdlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Assessment.Model.T_Assessment GetModel(int AssessmentId)
		{
			
			return dal.GetModel(AssessmentId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Assessment.Model.T_Assessment GetModelByCache(int AssessmentId)
		{
			
			string CacheKey = "T_AssessmentModel-" + AssessmentId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(AssessmentId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Assessment.Model.T_Assessment)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Assessment.Model.T_Assessment> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Assessment.Model.T_Assessment> DataTableToList(DataTable dt)
		{
			List<Assessment.Model.T_Assessment> modelList = new List<Assessment.Model.T_Assessment>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Assessment.Model.T_Assessment model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Assessment.Model.T_Assessment();					
													if(dt.Rows[n]["AssessmentId"].ToString()!="")
				{
					model.AssessmentId=int.Parse(dt.Rows[n]["AssessmentId"].ToString());
				}
																																if(dt.Rows[n]["MedicalRecordId"].ToString()!="")
				{
					model.MedicalRecordId=int.Parse(dt.Rows[n]["MedicalRecordId"].ToString());
				}
																																				model.Abstract1= dt.Rows[n]["Abstract1"].ToString();
																																model.Abstract2= dt.Rows[n]["Abstract2"].ToString();
																																model.Abstract3= dt.Rows[n]["Abstract3"].ToString();
																																model.Abstract4= dt.Rows[n]["Abstract4"].ToString();
																																model.Abstract5= dt.Rows[n]["Abstract5"].ToString();
																																model.Abstract6= dt.Rows[n]["Abstract6"].ToString();
																																model.Abstract7= dt.Rows[n]["Abstract7"].ToString();
																																model.Abstract8= dt.Rows[n]["Abstract8"].ToString();
																																model.Abstract9= dt.Rows[n]["Abstract9"].ToString();
																																model.Abstract10= dt.Rows[n]["Abstract10"].ToString();
																																model.Abstract11= dt.Rows[n]["Abstract11"].ToString();
																																model.Abstract12= dt.Rows[n]["Abstract12"].ToString();
																																model.Report= dt.Rows[n]["Report"].ToString();
																																model.PhysicalExamination= dt.Rows[n]["PhysicalExamination"].ToString();
																																model.ImagingExamination= dt.Rows[n]["ImagingExamination"].ToString();
																																model.SpecialCircumstances= dt.Rows[n]["SpecialCircumstances"].ToString();
																												if(dt.Rows[n]["CreateUserId"].ToString()!="")
				{
					model.CreateUserId=int.Parse(dt.Rows[n]["CreateUserId"].ToString());
				}
																																				model.CreateDate= dt.Rows[n]["CreateDate"].ToString();
																												if(dt.Rows[n]["UpdateUserId"].ToString()!="")
				{
					model.UpdateUserId=int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
				}
																																				model.UpdateDate= dt.Rows[n]["UpdateDate"].ToString();
																												if(dt.Rows[n]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(dt.Rows[n]["Valid"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}


		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
		
		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		
		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
#endregion
   
	}
}